package patrol.mobile.com.mobilepatrol.activity;

import android.content.Intent;
import android.content.res.Resources;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;

import java.util.ArrayList;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.adapter.FunTypeAdapter;
import patrol.mobile.com.mobilepatrol.bean.FunctionType;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;

/**
 * Created by apple on 17/9/27.
 */

public class MainActivity2 extends BaseActivity {
    @BindView(R.id.recycler)
    RecyclerView recyclerView;
    private BaseQuickAdapter mAdapter;
    private ArrayList<FunctionType> mList;
    private int imgs[] = {R.mipmap.l1,R.mipmap.l2,R.mipmap.l3,R.mipmap.l4,R.mipmap.l5,R.mipmap.l6};
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_main2;
    }

    @Override
    public void setListener() {
        mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(MainActivity2.this,MainActivity.class);
                intent.putExtra("id",mList.get(position));
                startActivity(intent);
                CommonUtil.openNewActivityAnim(MainActivity2.this,false);

            }
        });
    }

    @Override
    public void initData() {
        super.initData();
        recyclerView.setLayoutManager(new GridLayoutManager(this,4));
        Resources res =getResources();
        String[] fun =res.getStringArray(R.array.fun);
        mList = new ArrayList<>();
        for (int i=0;i<fun.length;i++){
            FunctionType type = new FunctionType();
            type.id = i;
            type.img = imgs[i];
            type.des = fun[i];
            mList.add(type);
        }
        mAdapter = new FunTypeAdapter(MainActivity2.this,mList);
        recyclerView.setAdapter(mAdapter);

    }

    @Override
    public void initTitle() {
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("首页");
    }
}
